<?php
/**
 *      [迷你云] (C)2009-2012 南京恒为网络科技.
 *   软件仅供研究与学习使用，如需商用，请访问www.miniyun.cn获得授权
 * 
 */
?>
<?php

class MUnmountController
extends MApplicationComponent
implements MIController
{
    
    public function invoke($uri=null)
    {
        $user   = MUserManager::getInstance()->getCurrentUser();
        $device = MUserManager::getInstance()->getCurrentDevice();
        $user_id = $user->user_id;
        $user_name = $user->user_name;
        $device_uuid = $device->user_device_uuid;
        $device_name = $device->user_device_name;
        
        $db_user_device = MUserDevice::queryUserDeviceByDevceUUIDAndUserID($user_id, $device_uuid);
        if ($db_user_device === false || count($db_user_device) <= 0) {
            throw new MFileopsException(
                                        FXP::t('the device does not match'),
                                        MConst::HTTP_CODE_403);
        }
        $id = $db_user_device[0]["id"];
        $ret = MUserDevice::deleteUserDeviceById($db_user_device[0]["id"]);
        if ($ret === false)
        {
            throw new MFileopsException(
                                        FXP::t('remove the device failure'),
                                        MConst::HTTP_CODE_403);
        }
        $response                   = array();
        $response["stataus"]        = "ok";
        $response["did"]            = $device_uuid;
        $response["display_name"]   = $device_name;
        $response["uid"]            = $user_id;
        $response["user_name"]      = $user_name;
        echo json_encode($response);
    }
}
?>